<template>
	<view>
		<view class="mt-5" v-if="u_loadmore">
			<u-loadmore status="loading" icon-type="circle" />
		</view>
		<view v-else>
			<view class="" v-for="(item,index) in addArray" :key="index">
				<view class="m-2 d-flex j-sb a-center" >
					<view class="py-4 span-9 text-center bg-white rounded-10">{{item.number}}</view>
					<view class="py-4 span-9 text-center bg-white rounded-10">{{item.price}}</view>
					<image class="icon_delete" src="../../static/images/goods/icon_delete.png" mode="" @click="del(index)"></image>
				</view>
			</view>	
			
			<view class="m-2 d-flex j-sb  a-center">
				<view class="py-4 span-9 text-center bg-white rounded-10">
					<input type="digit" value="" placeholder="请设置阶梯数量" v-model="adlist.number" />
				</view>
				<view class="py-4 span-9 text-center bg-white rounded-10">
					<input type="digit" value="" placeholder="请设置阶梯数量价格" v-model="adlist.price" />
				</view>
				<image class="icon_params_add" src="../../static/images/goods/icon_params_add.png" mode="" @click="addList"></image>
			</view>
			<view class="py-2 d-flex flex-column j-end  mr-2">
				<view class="d-flex j-end font-sm">购买数量达到阶梯数量时享受的优惠价格。</view>
			</view>
			<view class="bg-white py-2 w-100 position-fixed bottom-0 btn">
				<button type="warn" @click="preserve">保存</button>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked:true,
				adlist:{number:"",price:""},
				addArray:[],
				goods_id:'', // 商品ID
				u_loadmore:true, // 加载中
			}
		},
		methods: {
			
			addList(){
				if(!this.adlist.number==""&&!this.adlist.price==""){
					let arr={...this.adlist}
					this.addArray.push(arr)
					this.adlist = {number:"",price:""};
				}else{
					console.log("请输入内容")
				}
			},
			del(i){
				this.addArray.splice(i,1)
			},
			preserve(){
				console.log(this.addArray)
				this.$H.post("admin/merchant/goods/price/updateAll",{
					goods_id:this.goods_id,
					clear_volume_price:this.addArray?'yes':'no',
					volume_number:this.addArray
				}).then(res=>{
					uni.navigateBack({
						delta:1
					})
					var globalData = getApp().globalData.stair; //获取全局变量
					getApp().globalData.stair= '阶梯'; //修改全局变量
					console.log(res)
				})
				
			}
		},
		onLoad(e) {
			this.goods_id=e.goods_id
			this.$H.post("admin/merchant/goods/detail",{goods_id:e.goods_id}).then(res=>{
				this.addArray=res.data.volume_number
				this.u_loadmore=false 
			})
		}
	}
</script>

<style>
	.btn /deep/ button{
		width: 85%;
		border-radius: 50upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
	}
	.icon_delete{
		width: 40upx;
		height: 40upx;
	}
	.icon_params_add{
		width: 40upx;
		height: 40upx;
	}
</style>
